﻿package Cain.save
{
	import flash.events.Event;
	import flash.events.EventDispatcher;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.net.URLRequestHeader;
	import flash.net.URLRequestMethod;
	import flash.utils.ByteArray;
	
	/**
	 * ...
	 * @author Cain 2009
	 */
	public class  Save_jpg
	{
		private var ldr:URLLoader;
		private var php_url:String;
		private var jpg_data:ByteArray;
		private var path:String;
		public function Save_jpg(_ldr:URLLoader,_php_url:String,_jpg_data:ByteArray,_path:String) 
		{
			
			ldr = _ldr;
			php_url = _php_url;
			jpg_data = _jpg_data;
			path = _path;
			init();
		}
		
		private function init():void
		{
			var header:URLRequestHeader = new URLRequestHeader ("Content-type", "application/octet-stream");
			var jpgURLRequest:URLRequest = new URLRequest (php_url + "?name=" + path);
			jpgURLRequest.requestHeaders.push(header);
			jpgURLRequest.method = URLRequestMethod.POST;
			jpgURLRequest.data = jpg_data;
			//ldr.addEventListener(Event.COMPLETE, save_ok);
			ldr.load(jpgURLRequest);
		}
	}
	
}